<?php
$title = 'Ticket - #' . $ticket->getId();
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<table class="table">
    <tr>
        <th>Title</th><td><?php echo $this->escapeHtml($ticket->getTitle()); ?></td>
    </tr>
    <tr>
        <th>Category</th><td><?php echo $this->escapeHtml($ticket->getCategory()); ?></td>
    </tr>
    <tr>
        <th>Time</th><td><?php echo $this->escapeHtml($ticket->getTime()->format('d-m-Y H:i')); ?></td>
    </tr>
    <tr>
        <th>Description</th><td><?php echo $this->escapeHtml($ticket->getDescription()); ?></td>
    </tr>
    <tr>
        <th>User</th><td><?php echo $this->escapeHtml($ticket->getUser()->getLogin()); ?></td>
    </tr>
    <tr>
        <th>Closed</th><td><?php echo $this->escapeHtml($ticket->getClosed() ? 'Closed' : 'Open'); ?></td>
    </tr>
    <tr>
        <th>Updates</th>
        <td>
            <?php foreach ($ticket->getUpdates() as $update): ?>
                <p>
                    <?php /* TODO: TIME FORMAT! */ echo $this->escapeHtml($update->getTime()->format('d-m-Y H:i')); ?>
                    <?php /* TODO: MANY FETCHES! */ echo $this->escapeHtml($update->getAuthor()->getLogin()); ?>: 
                    <?php echo $this->escapeHtml($update->getText()); ?>
                </p>
            <?php endforeach; ?>



        </td>
    </tr>
</table>

<div>
    <h4>Update ticket</h4>
    <?php echo $this->form()->render($updateForm); ?>
</div>

<div>
    <h4><?php echo $ticket->getClosed() ? "Reopen ticket" : "Close ticket" ?></h4>
    <form action="<?php  echo $this->url('ticket', array(
        'action' => 'close',
        'id' => $ticket->getId(),
    )); ?>" method="post">
        <input type="submit" name="close" value="<?php echo $ticket->getClosed() ? "Reopen" : "Close" ?>" />
    </form>
</div>